﻿/*
* 
*
* 功 能： N/A
* 类 名： BDELEBOX
*
* Ver    变更日期             负责人  变更内容
* ───────────────────────────────────
* 
*/
using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;

using DQYT.HTDZ.IDAL;
using Maticsoft.DBUtility;
using DQYT.HTDZ.Model;


namespace DQYT.HTDZ.OracleDAL
{
	/// <summary>
	/// 数据访问类:BDELEBOX
	/// </summary>
	public partial class BDELEBOXDAL:IBDELEBOX
	{
		public BDELEBOXDAL()
		{}
		#region  BasicMethod

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(decimal PDGID)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from BDELEBOX");
			strSql.Append(" where PDGID=:PDGID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PDGID", OracleType.Number,22)			};
			parameters[0].Value = PDGID;

			return DbHelperOra.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public bool Add(BDELEBOXModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into BDELEBOX(");
			strSql.Append("PDGID,PDGXH,SCCJ,PDGLB,ISVALID,ISUSED)");
			strSql.Append(" values (");
			strSql.Append(":PDGID,:PDGXH,:SCCJ,:PDGLB,:ISVALID,:ISUSED)");
			OracleParameter[] parameters = {
					new OracleParameter(":PDGID", OracleType.Number,18),
					new OracleParameter(":PDGXH", OracleType.VarChar,30),
					new OracleParameter(":SCCJ", OracleType.VarChar,30),
					new OracleParameter(":PDGLB", OracleType.VarChar,30),
					new OracleParameter(":ISVALID", OracleType.Number,4),
					new OracleParameter(":ISUSED", OracleType.Number,4)};
			parameters[0].Value = model.PDGID;
			parameters[1].Value = model.PDGXH;
			parameters[2].Value = model.SCCJ;
			parameters[3].Value = model.PDGLB;
			parameters[4].Value = model.ISVALID;
			parameters[5].Value = model.ISUSED;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(BDELEBOXModel model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update BDELEBOX set ");
			strSql.Append("PDGXH=:PDGXH,");
			strSql.Append("SCCJ=:SCCJ,");
			strSql.Append("PDGLB=:PDGLB,");
			strSql.Append("ISVALID=:ISVALID,");
			strSql.Append("ISUSED=:ISUSED");
			strSql.Append(" where PDGID=:PDGID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PDGXH", OracleType.VarChar,30),
					new OracleParameter(":SCCJ", OracleType.VarChar,30),
					new OracleParameter(":PDGLB", OracleType.VarChar,30),
					new OracleParameter(":ISVALID", OracleType.Number,4),
					new OracleParameter(":ISUSED", OracleType.Number,4),
					new OracleParameter(":PDGID", OracleType.Number,18)};
			parameters[0].Value = model.PDGXH;
			parameters[1].Value = model.SCCJ;
			parameters[2].Value = model.PDGLB;
			parameters[3].Value = model.ISVALID;
			parameters[4].Value = model.ISUSED;
			parameters[5].Value = model.PDGID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(decimal PDGID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDELEBOX ");
			strSql.Append(" where PDGID=:PDGID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PDGID", OracleType.Number,22)			};
			parameters[0].Value = PDGID;

			int rows=DbHelperOra.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string PDGIDlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from BDELEBOX ");
			strSql.Append(" where PDGID in ("+PDGIDlist + ")  ");
			int rows=DbHelperOra.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BDELEBOXModel GetModel(decimal PDGID)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PDGID,PDGXH,SCCJ,PDGLB,ISVALID,ISUSED from BDELEBOX ");
			strSql.Append(" where PDGID=:PDGID ");
			OracleParameter[] parameters = {
					new OracleParameter(":PDGID", OracleType.Number,22)			};
			parameters[0].Value = PDGID;

			BDELEBOXModel model=new BDELEBOXModel();
			DataSet ds=DbHelperOra.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				return DataRowToModel(ds.Tables[0].Rows[0]);
			}
			else
			{
				return null;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public BDELEBOXModel DataRowToModel(DataRow row)
		{
			BDELEBOXModel model=new BDELEBOXModel();
			if (row != null)
			{
				if(row["PDGID"]!=null && row["PDGID"].ToString()!="")
				{
					model.PDGID=decimal.Parse(row["PDGID"].ToString());
				}
				if(row["PDGXH"]!=null)
				{
					model.PDGXH=row["PDGXH"].ToString();
				}
				if(row["SCCJ"]!=null)
				{
					model.SCCJ=row["SCCJ"].ToString();
				}
				if(row["PDGLB"]!=null)
				{
					model.PDGLB=row["PDGLB"].ToString();
				}
				if(row["ISVALID"]!=null && row["ISVALID"].ToString()!="")
				{
					model.ISVALID=decimal.Parse(row["ISVALID"].ToString());
				}
				if(row["ISUSED"]!=null && row["ISUSED"].ToString()!="")
				{
					model.ISUSED=decimal.Parse(row["ISUSED"].ToString());
				}
			}
			return model;
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select PDGID,PDGXH,SCCJ,PDGLB,ISVALID,ISUSED ");
			strSql.Append(" FROM BDELEBOX ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperOra.Query(strSql.ToString());
		}

		/// <summary>
		/// 获取记录总数
		/// </summary>
		public int GetRecordCount(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) FROM BDELEBOX ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			object obj = DbHelperSQL.GetSingle(strSql.ToString());
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetListByPage(string strWhere, string orderby, int startIndex, int endIndex)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("SELECT * FROM ( ");
			strSql.Append(" SELECT ROW_NUMBER() OVER (");
			if (!string.IsNullOrEmpty(orderby.Trim()))
			{
				strSql.Append("order by T." + orderby );
			}
			else
			{
				strSql.Append("order by T.PDGID desc");
			}
			strSql.Append(")AS Row, T.*  from BDELEBOX T ");
			if (!string.IsNullOrEmpty(strWhere.Trim()))
			{
				strSql.Append(" WHERE " + strWhere);
			}
			strSql.Append(" ) TT");
			strSql.AppendFormat(" WHERE TT.Row between {0} and {1}", startIndex, endIndex);
			return DbHelperOra.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "BDELEBOX";
			parameters[1].Value = "PDGID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperOra.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  BasicMethod
		#region  ExtensionMethod

		#endregion  ExtensionMethod
	}
}

